<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //1.数组去重
        let arr1 = [1, 2, 3, 4, 5, 6, 1, 2, 8];
        let s1 = [...new Set(arr1)];
        console.log(s1);
        //2.交集
        let arr2 = [1, 2, 3, 4, 7];
        // let res = [...new Set(arr1)].filter(item => {
        //     let s2 = new Set(arr2);
        //     if (s2.has(item)) {
        //         return true
        //     } else {
        //         return false
        //     }
        // })
        let res = [...new Set(arr1)].filter(item => new Set(arr2).has(item));
        console.log(res);
        //3.并集
        let union = [...new Set([...arr1, ...arr2])];
        console.log(union);
        //4.差集
        let uni = [...new Set(arr1)].filter(item => !(new Set(arr2).has(item)));
        console.log(uni);
    </script>
</body>

</html>